package com.libing.service.impl;

import com.libing.base.BaseDao;
import com.libing.base.BaseService;
import com.libing.dao.UserDao;
import com.libing.entity.User;
import com.libing.enums.StateEnum;
import com.libing.service.UserService;
import com.libing.util.MD5Utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @Description:
 * @Auther: LEE
 * @Date: Create in 2018/3/3 11:18
 */
@Service
public class UserServiceImpl extends BaseService<User> implements UserService {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private UserDao userDao;

    public StateEnum save(User user) {
        user.setPassword(MD5Utils.getMD5(user.getPassword()));
        return getCUDStatus(userDao.insert(user));
    }

    @Override
    public StateEnum remove(Long id) {
        return getCUDStatus(userDao.delete(id));
    }

    @Override
    public StateEnum modify(User user) {
        user.setModifyTime(new Date());
        return getCUDStatus(userDao.update(user));
    }

    @Override
    public User detail(Long id) {
        return null;
    }

    @Override
    public User queryByName(String username) {
        return userDao.selectByName(username);
    }

    @Override
    protected BaseDao<User> getBaseDao() {
        return this.userDao;
    }

}
